package sz.szsmk.citizencard.ui.activity;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.chenenyu.router.annotation.Route;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.UserAddMyCardBinding;
import sz.szsmk.citizencard.dialog.SuccessDialog;
import sz.szsmk.citizencard.mvp.contract.IUserAppendContact;
import sz.szsmk.citizencard.mvp.presenter.UserAppendPresenter;
import sz.szsmk.citizencard.ui.base.IBaseActivity;
import sz.szsmk.citizencard.util.SharedPreferencesTool;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/7/25 17:44
 * description:
 */
@Route("addmycard")
public class UserAddMyCardActivity extends IBaseActivity<UserAppendPresenter, UserAddMyCardBinding>
        implements IUserAppendContact.IUserAppendView, View.OnClickListener {

    private LinearLayout userXxnkLl;
    private LinearLayout userZzkLl;
    private LinearLayout userHmxxnkLl;
    private LinearLayout userWhxfkLl;
    private String mZzk;
    private String mXxnk;

    @Override
    protected int attachLayoutRes() {
        return R.layout.user_add_my_card;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initViews() {

        dataBinding.titleLayout.addBack.setOnClickListener(this);
        dataBinding.titleLayout.addBjTv.setOnClickListener(this);
        dataBinding.userCancelXxnk.setOnClickListener(this);
        dataBinding.userCancelZzk.setOnClickListener(this);
        dataBinding.userXxnkTv.setOnClickListener(this);
        dataBinding.userWhxfTv.setOnClickListener(this);
        userXxnkLl = dataBinding.userXxnkLl;
        userZzkLl = dataBinding.userZzkLl;
        userHmxxnkLl = dataBinding.userHmxxnkLl;
        userWhxfkLl = dataBinding.userWhxfkLl;
        String zzk = SharedPreferencesTool.getString(this, "zzk", "0");
        String xxnk = SharedPreferencesTool.getString(this, "xxnk", "0");

        if (zzk.equals("0")) {
            userZzkLl.setVisibility(View.GONE);
            userWhxfkLl.setVisibility(View.VISIBLE);

            mZzk = zzk;
        } else {
            userZzkLl.setVisibility(View.VISIBLE);
            userWhxfkLl.setVisibility(View.GONE);
            mZzk = zzk;
        }

        if (xxnk.equals("0")) {
            userXxnkLl.setVisibility(View.GONE);
            userHmxxnkLl.setVisibility(View.VISIBLE);
            mXxnk = xxnk;
        } else {
            userXxnkLl.setVisibility(View.VISIBLE);
            userHmxxnkLl.setVisibility(View.GONE);
            mXxnk = xxnk;
        }

    }

    @Override
    protected void updateViews() {

    }

    @Override
    public void updataError(String message) {

    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.add_back) {
            finish();
        } else if (id == R.id.add_bj_tv) {
            SharedPreferencesTool.saveString(this, "zzk", mZzk);
            SharedPreferencesTool.saveString(this, "xxnk", mXxnk);
            final SuccessDialog dialog = new SuccessDialog(this, "操作成功");

            dialog.show();
            new Thread() {
                @Override
                public void run() {
                    super.run();
                    try {
                        Thread.sleep(1000);//休眠3秒
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    dialog.cancel();
                    finish();
                }
            }.start();
        } else if (id == R.id.user_cancel_xxnk) {
            userXxnkLl.setVisibility(View.GONE);
            userHmxxnkLl.setVisibility(View.VISIBLE);
            mXxnk = "0";
        } else if (id == R.id.user_cancel_zzk) {
            userWhxfkLl.setVisibility(View.VISIBLE);
            userZzkLl.setVisibility(View.GONE);
            mZzk = "0";
        } else if (id == R.id.user_xxnk_tv) {
            userXxnkLl.setVisibility(View.VISIBLE);
            userHmxxnkLl.setVisibility(View.GONE);

            mXxnk = "1";
        } else if (id == R.id.user_whxf_tv) {
            Toast.makeText(this, "添加文化消费卡", Toast.LENGTH_SHORT).show();
            userZzkLl.setVisibility(View.VISIBLE);
            userWhxfkLl.setVisibility(View.GONE);
            mZzk = "1";
        }
    }
}
